home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / vol16n13.zip / OPENTR.ZIP / OT_SRC.ZIP / FILTDLG.CPP < prev    next >
C/C++ Source or Header  |  1997-05-26  |  6KB  |  217 lines

  1. // FiltDlg.cpp : implementation file
  2. //
  3. // This module implements the Filter Options dialog.
  4. //
  5. // OpenTrap Version 1.00 by Gregory A. Wolking
  6. // Copyright ⌐ 1997 Ziff-Davis Publishing
  7. // First published in PC Magazine, US Edition, July 1997.
  8.  
  9. #include "stdafx.h"
  10. #include "OpenTrap.h"
  11. #include "FiltDlg.h"
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CFilterDlg dialog
  20.  
  21.  
  22. CFilterDlg::CFilterDlg(CWnd* pParent /*=NULL*/)
  23.     : CDialog(CFilterDlg::IDD, pParent)
  24. {
  25.     //{{AFX_DATA_INIT(CFilterDlg)
  26.     m_intShow = -1;
  27.     m_strBaseName = _T("");
  28.     m_strExt = _T("");
  29.     m_strModuleName = _T("");
  30.     m_bBaseName = FALSE;
  31.     m_bErrorsOnly = FALSE;
  32.     m_bExt = FALSE;
  33.     m_bModuleName = FALSE;
  34.     m_bSaveSettings = FALSE;
  35.     //}}AFX_DATA_INIT
  36. }
  37.  
  38.  
  39. void CFilterDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41.     CDialog::DoDataExchange(pDX);
  42. //    CDialog::DoDataExchange(pDX);
  43.     //{{AFX_DATA_MAP(CFilterDlg)
  44.     DDX_Control(pDX, IDC_chkModuleName, m_chkModuleName);
  45.     DDX_Control(pDX, IDC_chkExt, m_chkExt);
  46.     DDX_Control(pDX, IDC_chkBaseName, m_chkBaseName);
  47.     DDX_Control(pDX, IDC_txtBaseName, m_txtBaseName);
  48.     DDX_Control(pDX, IDC_txtModuleName, m_txtModuleName);
  49.     DDX_Control(pDX, IDC_txtExt, m_txtExt);
  50.     DDX_Radio(pDX, IDC_optShow1, m_intShow);
  51.     DDX_Text(pDX, IDC_txtBaseName, m_strBaseName);
  52.     DDX_Text(pDX, IDC_txtExt, m_strExt);
  53.     DDX_Text(pDX, IDC_txtModuleName, m_strModuleName);
  54.     DDV_MaxChars(pDX, m_strModuleName, 8);
  55.     DDX_Check(pDX, IDC_chkBaseName, m_bBaseName);
  56.     DDX_Check(pDX, IDC_chkErrorsOnly, m_bErrorsOnly);
  57.     DDX_Check(pDX, IDC_chkExt, m_bExt);
  58.     DDX_Check(pDX, IDC_chkModuleName, m_bModuleName);
  59.     DDX_Check(pDX, IDC_chkSaveSettings, m_bSaveSettings);
  60.     //}}AFX_DATA_MAP
  61. }
  62.  
  63.  
  64. BEGIN_MESSAGE_MAP(CFilterDlg, CDialog)
  65.     //{{AFX_MSG_MAP(CFilterDlg)
  66.     ON_BN_CLICKED(IDC_chkBaseName, OnchkBaseName)
  67.     ON_BN_CLICKED(IDC_chkExt, OnchkExt)
  68.     ON_BN_CLICKED(IDC_chkModuleName, OnchkModuleName)
  69.     ON_BN_CLICKED(IDC_cmdReset, OncmdReset)
  70.     ON_WM_CONTEXTMENU()
  71.     //}}AFX_MSG_MAP
  72.     ON_COMMAND(ID_CONTEXT_HELP, OnContextHelp)
  73. END_MESSAGE_MAP()
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CFilterDlg message handlers
  77.  
  78. void CFilterDlg::OnchkBaseName() 
  79. {
  80.     if (m_chkBaseName.GetCheck())
  81.     {
  82.         m_txtBaseName.EnableWindow(TRUE);
  83.         m_txtBaseName.SetFocus();
  84.     }
  85.     else
  86.     {
  87.         m_txtBaseName.EnableWindow(FALSE);
  88.     }
  89. }
  90.  
  91. void CFilterDlg::OnchkExt() 
  92. {
  93.     if (m_chkExt.GetCheck())
  94.     {
  95.         m_txtExt.EnableWindow(TRUE);
  96.         m_txtExt.SetFocus();
  97.     }
  98.     else
  99.     {
  100.         m_txtExt.EnableWindow(FALSE);
  101.     }
  102. }
  103.  
  104. void CFilterDlg::OnchkModuleName() 
  105. {
  106.     if (m_chkModuleName.GetCheck())
  107.     {
  108.         m_txtModuleName.EnableWindow(TRUE);
  109.         m_txtModuleName.SetFocus();
  110.     }
  111.     else
  112.     {
  113.         m_txtModuleName.EnableWindow(FALSE);
  114.     }
  115. }
  116.  
  117. void CFilterDlg::OncmdReset() 
  118. {
  119.     m_intShow = 0;
  120.     m_bExt = m_bBaseName = m_bModuleName = m_bErrorsOnly = FALSE;
  121.     m_strExt.Empty();
  122.     m_strBaseName.Empty();
  123.     m_strModuleName.Empty();
  124.     m_txtExt.EnableWindow(FALSE);
  125.     m_txtBaseName.EnableWindow(FALSE);
  126.     m_txtModuleName.EnableWindow(FALSE);
  127.     UpdateData(FALSE);
  128. }
  129.  
  130. BOOL CFilterDlg::OnInitDialog() 
  131. {
  132.     CDialog::OnInitDialog();
  133.  
  134.     // Make sure edit controls are enabled according to their
  135.     // corresponding check box settings.
  136.     m_txtBaseName.EnableWindow(m_bBaseName);
  137.     m_txtExt.EnableWindow(m_bExt);
  138.     m_txtModuleName.EnableWindow(m_bModuleName);
  139.     return TRUE;
  140. }
  141.  
  142. // Handle data validation when user clicks OK.
  143. // If any fields are invalid, program presents an appropriate error message,
  144. // puts input focus on the invalid field, and leaves the dialog open.
  145. void CFilterDlg::OnOK() 
  146. {
  147.     int pos;
  148.     UpdateData(TRUE);
  149.     // Make sure base name is not blank, and if it contains a "*"
  150.     // wildcard, it must be at the end of the string.
  151.     if (m_bBaseName)
  152.     {
  153.         if (m_strBaseName.IsEmpty())
  154.         {
  155.             AfxMessageBox(IDP_NO_BLANK_FILTERS);
  156.             return;
  157.         }
  158.         pos = m_strBaseName.Find('*');
  159.         if (pos >= 0 && pos != m_strBaseName.GetLength() - 1)
  160.         {
  161.             AfxMessageBox(IDP_BAD_FILENAME);
  162.             m_txtBaseName.SetFocus();
  163.             return;
  164.         }
  165.     }
  166.     // For extensions, again just make sure that the "*" wildcard appears
  167.     // only at the end of the string.
  168.     if (m_bExt)
  169.     {
  170.         pos = m_strExt.Find('*');
  171.         if (pos >= 0 && pos != m_strExt.GetLength() - 1)
  172.         {
  173.             AfxMessageBox(IDP_BAD_FILENAME);
  174.             m_txtExt.SetFocus();
  175.             return;
  176.         }
  177.     }
  178.     // In contrast, Module Name strings cannot include wildcards.
  179.     if (m_bModuleName)
  180.     {
  181.         if (m_strModuleName.Find('?') >= 0 || m_strModuleName.Find('*') >= 0)
  182.         {
  183.             AfxMessageBox(IDP_BAD_MODULE_NAME);
  184.             m_txtModuleName.SetFocus();
  185.             return;
  186.         }
  187.     }
  188.     CDialog::OnOK();
  189. }
  190.  
  191. // Handler for right-mouse help.
  192. void CFilterDlg::OnContextMenu(CWnd* pWnd, CPoint point)
  193. {
  194.     CPoint ptClient = point;
  195.     CWnd* wndTarget;
  196.     UINT id = 0;
  197.     ScreenToClient(&ptClient);
  198.     wndTarget = ChildWindowFromPoint(ptClient, CWP_SKIPTRANSPARENT);
  199.     if (wndTarget == this)
  200.         wndTarget = ChildWindowFromPoint(ptClient);
  201.     if (wndTarget)
  202.         id = wndTarget->GetDlgCtrlID();
  203.     if (id == 0 || id == IDOK || id == IDCANCEL)
  204.         return;
  205.     else
  206.         m_intHelpContext = id + 0x40000;
  207.     CMenu my_menu;
  208.     my_menu.CreatePopupMenu();
  209.     my_menu.AppendMenu(MF_ENABLED, ID_CONTEXT_HELP, "What's this?");
  210.     my_menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, this);
  211. }
  212.  
  213. void CFilterDlg::OnContextHelp()
  214. {
  215.     WinHelp(m_intHelpContext, HELP_CONTEXTPOPUP);
  216. }
  217.